<!DOCTYPE html>


<html lang="zh-CN">


<head>
  <meta charset="utf-8" />
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
     
  </title>
  <meta name="generator" content="hexo-theme-ayer">
  
  <link rel="shortcut icon" href="https://pic.imgdb.cn/item/5f7dd84c1cd1bbb86b7c682b.jpg" />
  
  
<link rel="stylesheet" href="/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  

<link rel="alternate" href="/atom.xml" title="光" type="application/atom+xml">
</head>

</html>

<body>
  <div id="app">
    
      
    <main class="content on">
      
<section class="cover">
    
  <div class="cover-frame">
    <div class="bg-box">
      <img src="/images/cover1.jpg" alt="image frame" />
    </div>
    <div class="cover-inner text-center text-white">
      <h1><a href="/">光</a></h1>
      <div id="subtitle-box">
        
        <span id="subtitle"></span>
        
      </div>
      <div>
        
      </div>
    </div>
  </div>
  <div class="cover-learn-more">
    <a href="javascript:void(0)" class="anchor"><i class="ri-arrow-down-line"></i></a>
  </div>
</section>



<script src="https://cdn.jsdelivr.net/npm/typed.js@2.0.11/lib/typed.min.js"></script>


<!-- Subtitle -->

  <script>
    try {
      var typed = new Typed("#subtitle", {
        strings: ['日拱一卒无有尽，功不唐捐终入海', '', ''],
        startDelay: 0,
        typeSpeed: 200,
        loop: true,
        backSpeed: 100,
        showCursor: true
      });
    } catch (err) {
      console.log(err)
    }
  </script>
  
<div id="main">
  <section class="outer">
  
  

<div class="notice" style="margin-top:50px">
    <i class="ri-heart-fill"></i>
    <div class="notice-content" id="broad"></div>
</div>
<script type="text/javascript">
    fetch('https://v1.hitokoto.cn')
        .then(response => response.json())
        .then(data => {
            document.getElementById("broad").innerHTML = data.hitokoto;
        })
        .catch(console.error)
</script>

<style>
    .notice {
        padding: 20px;
        border: 1px dashed #e6e6e6;
        color: #969696;
        position: relative;
        display: inline-block;
        width: 100%;
        background: #fbfbfb50;
        border-radius: 10px;
    }

    .notice i {
        float: left;
        color: #999;
        font-size: 16px;
        padding-right: 10px;
        vertical-align: middle;
        margin-top: -2px;
    }

    .notice-content {
        display: initial;
        vertical-align: middle;
    }
</style>
  
  <article class="articles">
    
    
    
    
    <article
  id="post-springCloud-Alibaba-2"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2020/10/25/springCloud-Alibaba-2/"
    >springCloud Alibaba(2)</a> 
</h2>
 

    </header>
     
    <div class="article-meta">
      <a href="/2020/10/25/springCloud-Alibaba-2/" class="article-date">
  <time datetime="2020-10-25T14:04:16.000Z" itemprop="datePublished">2020-10-25</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/srpingCloud-Alibaba/">srpingCloud Alibaba</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h2 id="Nacos服务注册与发现"><a href="#Nacos服务注册与发现" class="headerlink" title="Nacos服务注册与发现"></a>Nacos服务注册与发现</h2> 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/srpingCloud-Alibaba/" rel="tag">srpingCloud Alibaba</a></li></ul>

    </footer>
  </div>

    
 
   
</article>

    
    <article
  id="post-WebService简单案例"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2020/10/25/WebService%E7%AE%80%E5%8D%95%E6%A1%88%E4%BE%8B/"
    >WebService简单案例</a> 
</h2>
 

    </header>
     
    <div class="article-meta">
      <a href="/2020/10/25/WebService%E7%AE%80%E5%8D%95%E6%A1%88%E4%BE%8B/" class="article-date">
  <time datetime="2020-10-25T07:09:21.000Z" itemprop="datePublished">2020-10-25</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/webService/">webService</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h2 id="WebService简介"><a href="#WebService简介" class="headerlink" title="WebService简介"></a>WebService简介</h2><p>​    Web Service技术， 能使得运行在不同机器上的不同应用无须借助附加的、专门的第三方软件或硬件， 就可相互交换数据或集成。依据Web Service规范实施的应用之间， 无论它们所使用的语言、 平台或内部协议是什么， 都可以相互交换数据。</p>
<p>​    简单的说，WebService就是一种跨编程语言和跨操作系统平台的远程调用技术。所谓跨编程语言和跨操作平台，就是说服务端程序采用java编写，客户端程序则可以采用其他编程语言编写，反之亦然。跨操作系统平台则是指服务端程序和客户端程序可以在不同的操作系统上运行。 远程调用，就是一台计算机的应用可以调用其他计算机上的应用。例如：支付宝，支付宝并没有银行卡等数据，它只是去调用银行提供的接口来获得数据。还有天气预报等，也是气象局把自己的系统服务以webservice服务的形式暴露出来，让第三方网站和程序可以调用这些服务功能。</p>
<h2 id="WebService原理"><a href="#WebService原理" class="headerlink" title="WebService原理"></a><strong>WebService原理</strong></h2><p><strong>XML,SOAP和WSDL就是构成WebService平台的三大技术 。</strong></p>
<ul>
<li>WebService采用Http协议来在客户端和服务端之间传输数据。WebService使用XML来封装数据，XML主要的优点在于它是跨平台的。</li>
<li>WebService通过HTTP协议发送请求和接收结果时，发送的请求内容和结果内容都采用XML格式封装，并增加了一些特定的HTTP消息头，以说明HTTP消息的内容格式，这些特定的HTTP消息头和XML内容格式就是SOAP协议规定的。</li>
<li>WebService服务器端首先要通过一个WSDL文件来说明自己有什么服务可以对外调用。简单的说，WSDL就像是一个说明书，用于描述WebService及其方法、参数和返回值。 WSDL文件保存在Web服务器上，通过一个url地址就可以访问到它。客户端要调用一个WebService服务之前，要知道该服务的WSDL文件的地址。WebService服务提供商可以通过两种方式来暴露它的WSDL文件地址：1.注册到UDDI服务器，以便被人查找；2.直接告诉给客户端调用者。</li>
</ul>
<h2 id="基于Idea案例"><a href="#基于Idea案例" class="headerlink" title="基于Idea案例"></a>基于Idea案例</h2><h6 id="1-新建普通maven项目"><a href="#1-新建普通maven项目" class="headerlink" title="1.新建普通maven项目"></a>1.新建普通maven项目</h6><pre><code> 建立包：com.hs.service    </code></pre>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.hs.service;</span><br><span class="line"><span class="keyword">import</span> javax.jws.WebMethod;</span><br><span class="line"><span class="keyword">import</span> javax.jws.WebService;</span><br><span class="line"><span class="keyword">import</span> javax.xml.ws.Endpoint;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> *WebService服务发布</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@WebService</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">UserService</span> </span>&#123;</span><br><span class="line">    <span class="meta">@WebMethod</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getUser</span><span class="params">(<span class="keyword">long</span> userId)</span></span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;hello &quot;</span> + userId;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        <span class="comment">//发布我们的接口</span></span><br><span class="line">        Endpoint.publish(<span class="string">&quot;http://localhost:8089/service/UserService&quot;</span>,<span class="keyword">new</span> UserService());</span><br><span class="line">        System.out.println(<span class="string">&quot;服务发布成功！&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>运行main后</p>
<p>可以访问<a target="_blank" rel="noopener" href="http://localhost:8089/service/UserService%EF%BC%8C%E5%A6%82%EF%BC%9A">http://localhost:8089/service/UserService，如：</a></p>
</blockquote>
<p><img src="https://pic.downk.cc/item/5f9526a31cd1bbb86b8bd4c3.jpg"></p>
<blockquote>
<p>这里的@WebService及@WebMethod注解都是java自带的webService注解</p>
</blockquote>
<h6 id="2-建立客户端"><a href="#2-建立客户端" class="headerlink" title="2.建立客户端"></a>2.建立客户端</h6><p><img src="https://pic.downk.cc/item/5f9525eb1cd1bbb86b8bb3d9.jpg"></p>
<p><img src="https://pic.downk.cc/item/5f9526161cd1bbb86b8bbbc0.jpg"></p>
<blockquote>
<p>需要更改Web Service wsdl url，及package prefix</p>
</blockquote>
<p>然后会默认生成几个类</p>
<p><img src="https://pic.downk.cc/item/5f9527151cd1bbb86b8bed1f.jpg"></p>
<p>这里的Client测试类为:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.hs;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.hs.service.UserService;</span><br><span class="line"><span class="keyword">import</span> com.hs.service.UserServiceServiceLocator;</span><br><span class="line"><span class="keyword">import</span> javax.xml.rpc.ServiceException;</span><br><span class="line"><span class="keyword">import</span> java.rmi.RemoteException;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Client</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> <span class="keyword">throws</span> ServiceException, RemoteException </span>&#123;</span><br><span class="line">        UserServiceServiceLocator userServiceServiceLocator</span><br><span class="line">                = <span class="keyword">new</span> UserServiceServiceLocator();</span><br><span class="line"></span><br><span class="line">        UserService userService = userServiceServiceLocator.getUserServicePort();</span><br><span class="line">        String result = userService.getUser(<span class="number">22L</span>);</span><br><span class="line">        System.out.println(<span class="string">&quot;result: &quot;</span> + result);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>这样就简简单单能够调用服务端发布的服务了</p>
<blockquote>
<p>client也是远程RPC调用，通过代理类来返回结果。</p>
</blockquote>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/webService/" rel="tag">webService</a></li></ul>

    </footer>
  </div>

    
 
   
</article>

    
    <article
  id="post-springCloud-Alibaba"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2020/10/25/springCloud-Alibaba/"
    >springCloud Alibaba(1)</a> 
</h2>
 

    </header>
     
    <div class="article-meta">
      <a href="/2020/10/25/springCloud-Alibaba/" class="article-date">
  <time datetime="2020-10-25T05:47:23.000Z" itemprop="datePublished">2020-10-25</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/srpingCloud-Alibaba/">srpingCloud Alibaba</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h2 id="微服务架构的演变"><a href="#微服务架构的演变" class="headerlink" title="微服务架构的演变"></a>微服务架构的演变</h2><p>单体架构  <strong>→</strong> 分布式架构  <strong>→</strong>  SOA面向服务架构 <strong>→</strong> 微服务架构 <strong>→</strong> 服务网格（Service Mesh）</p>
<h4 id="传统的单体架构模式"><a href="#传统的单体架构模式" class="headerlink" title="传统的单体架构模式"></a>传统的单体架构模式</h4><pre><code> 单体应用，之前的ssm项目，前后不分离、部署到同一台服务器，这种。</code></pre>
<ul>
<li><p>优点： 开发、运维简单。</p>
<ul>
<li>缺点：<ul>
<li>开发过程中各个模块耦合高、容易相互影响，适合于人少开发，人多不适合。<ul>
<li>单个服务bug导致整个项目不可用。    </li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>应用场景： OA、官网、开发人员少等小项目。</p>
<h4 id="分布式架构模式"><a href="#分布式架构模式" class="headerlink" title="分布式架构模式"></a>分布式架构模式</h4><p>​    基于传统架构模式演变而来，根据原业务进行拆分，如拆分为:订单系统、支付系统、用户系统 等等。这种降低了代码的耦合度， 适用于团队开发。</p>
<p>​    常见的如一个大的系统，拆分成多个小的独立的系统，根据不同的域名访问不同的系统</p>
<p>​    <a target="_blank" rel="noopener" href="http://www.perty.com/">www.perty.com</a></p>
<p>​    <a target="_blank" rel="noopener" href="http://www.bbs.perty.com/">www.bbs.perty.com</a></p>
<h4 id="SOA面向服务架构模式"><a href="#SOA面向服务架构模式" class="headerlink" title="SOA面向服务架构模式"></a>SOA面向服务架构模式</h4><p>​    SOA面向服务架构模式也是基于分布式架构模式演变而来，俗称服务话，也就是面向服务开发，将共同的业务逻辑抽取成一个单独的服务提供给其它系统使用。</p>
<ul>
<li>SOA架构模式传输协议采用SOAP协议（Http/Https+XML）实现传输，所以所后面使用json替代了xml方式</li>
<li>SOA一般使用WebService，或者ESB（企业服务总线），这种技术传统项目用的多，但也在逐渐被替代。</li>
</ul>
<h6 id="WebService架构模式："><a href="#WebService架构模式：" class="headerlink" title="WebService架构模式："></a>WebService架构模式：</h6><p>​        wsdl: 接口的信息、地址、参数。<a href="/2020/10/25/WebService%E7%AE%80%E5%8D%95%E6%A1%88%E4%BE%8B/" title="WebService简单案例">WebService简单案例</a></p>
<p>​        <img src="https://pic.downk.cc/item/5f951cd61cd1bbb86b89d521.jpg"></p>
<h6 id="SOA架构的特点"><a href="#SOA架构的特点" class="headerlink" title="SOA架构的特点"></a>SOA架构的特点</h6><ul>
<li>采用SOAP协议通讯，xml作为传输体，有过多的冗余信息，传输数据量大，影响调用效率。</li>
<li>服务化管理及治理设施不够完善，没有相应的服务管理及治理的组件。</li>
<li>这个一般前端不方便调用这种服务，实际工作中也是后台来调用这种服务。</li>
</ul>
<h4 id="微服务架构模式"><a href="#微服务架构模式" class="headerlink" title="微服务架构模式"></a>微服务架构模式</h4><p>   微服务架构模式就是从SOA架构演变而来，比SOA架构对服务的拆分粒度会更加细。服务之间通过Restful协议交互，数据交互通过HTTP + JSON格式实现传输。也解决了多个语言平台通讯的问题。</p>
<p><img src="https://pic.downk.cc/item/5f952dd31cd1bbb86b8d3a8b.jpg"></p>
<blockquote>
<p>这样一套服务 ，各类客户端都可以使用。</p>
</blockquote>
<ul>
<li>轻量级，单独服务、单独开发/运维</li>
<li>跨平台、跨语言</li>
<li>服务之间互不影响</li>
</ul>
<h4 id="SOA与微服务架构的区别"><a href="#SOA与微服务架构的区别" class="headerlink" title="SOA与微服务架构的区别"></a>SOA与微服务架构的区别</h4><ul>
<li>通讯协议<ul>
<li>SOA采用XML传输</li>
<li>微服务采用json传输</li>
</ul>
</li>
<li>服务拆分粒度<ul>
<li>微服务拆分需要更细致些，而且每个服务都有自己的数据库、redis、MQ等，都是独立部署的。</li>
</ul>
</li>
<li>迭代<ul>
<li>微服务架构模式比SOA架构模式更加适合于互联网公司。敏捷、高效。</li>
</ul>
</li>
</ul>
<h4 id="微服务架构存在的问题"><a href="#微服务架构存在的问题" class="headerlink" title="微服务架构存在的问题"></a>微服务架构存在的问题</h4><ul>
<li>分布式事务解决方案（rabbitMq,rocketMq）,主要为了最终一致性。</li>
<li>分布式任务调度平台（XXL-Job,AkibabaCloud Scheduler,elastic-job）</li>
<li>分布式服务注册中心（eureka、zookeeper、Nacos）</li>
<li>分布式日志采集系统（Elk + kafka）</li>
<li>分布式服务追踪与调用链系统 Zipkin</li>
<li>分布式服务配置中心(springCloud config、Nacos、zookeeper…)</li>
</ul>
<h4 id="SpringCloud介绍"><a href="#SpringCloud介绍" class="headerlink" title="SpringCloud介绍"></a>SpringCloud介绍</h4><p>​    SpringCloud是一整套的微服务架构的解决方案。</p>
<p>​    SrpingCloud第一代其实是利用了Netflix公司的开源组件整合成一个微服务解决框架。</p>
<p>​    SpringCloud第二代自研组件，和国内开源融合。</p>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/srpingCloud-Alibaba/" rel="tag">srpingCloud Alibaba</a></li></ul>

    </footer>
  </div>

    
 
   
</article>

    
    <article
  id="post-Java对象头"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2020/10/08/Java%E5%AF%B9%E8%B1%A1%E5%A4%B4/"
    >对象的内存布局</a> 
</h2>
 

    </header>
     
    <div class="article-meta">
      <a href="/2020/10/08/Java%E5%AF%B9%E8%B1%A1%E5%A4%B4/" class="article-date">
  <time datetime="2020-10-08T07:31:06.000Z" itemprop="datePublished">2020-10-08</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h4 id="一、概述"><a href="#一、概述" class="headerlink" title="一、概述"></a>一、概述</h4><ol>
<li><p>不同的对象有着不同的对象大小，理解java对象的内存布局知识，有利于对对象内存有更清晰的理解与控制。</p>
</li>
<li><p>众所周知synchronized与对象头有着莫大的渊源，了解了java对象头，有利于理解synchronized原理。</p>
</li>
</ol>
<h4 id="二、环境准备"><a href="#二、环境准备" class="headerlink" title="二、环境准备"></a>二、环境准备</h4><p>os:  win_x64</p>
<p>java环境:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">java version &quot;1.8.0_201&quot;</span><br><span class="line">Java(TM) SE Runtime Environment (build 1.8.0_201-b09)</span><br><span class="line">Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)</span><br></pre></td></tr></table></figure>



<p>maven引入用于对象内存分析的工具</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">    &lt;dependency&gt;</span><br><span class="line">        &lt;groupId&gt;org.openjdk.jol&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;jol-core&lt;/artifactId&gt;</span><br><span class="line">        &lt;version&gt;0.9&lt;/version&gt;</span><br><span class="line">    &lt;/dependency&gt;</span><br><span class="line">    </span><br><span class="line"><span class="comment">//示例</span></span><br><span class="line">Object o = <span class="keyword">new</span> Object();</span><br><span class="line">System.out.println(ClassLayout.parseInstance(o).toPrintable());</span><br></pre></td></tr></table></figure>



<h4 id="三、对象的内存布局"><a href="#三、对象的内存布局" class="headerlink" title="三、对象的内存布局"></a>三、对象的内存布局</h4><h6 id="对象大小"><a href="#对象大小" class="headerlink" title=" 对象大小"></a><img src="https://pic.downk.cc/item/5f7ee14e1cd1bbb86bb8bd91.png" alt="img"> 对象大小</h6><p>​    1. object对象大小</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Object o = <span class="keyword">new</span> Object();</span><br><span class="line">System.out.println(ClassLayout.parseInstance(o).toPrintable());</span><br></pre></td></tr></table></figure>

<p><img src="https://pic.downk.cc/item/5f7ee1d11cd1bbb86bb8df24.png" alt="IMG"></p>
<p>​    这里在64位机器上默认会开启指针压缩的功能 -XX:+UseCompressedOops ，这里我关了试试</p>
<p>​    增加jvm运行参数 -XX:-UseCompressedOops <img src="https://pic.downk.cc/item/5f7ee2631cd1bbb86bb91525.png" alt="IMG"></p>
<p>  所以实际上64位机器上关闭指针压缩的话，class pointer占用8字节。</p>
<p>​    2. 普通对象</p>
   <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Student</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> String name = <span class="string">&quot;jerry&quot;</span>;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">int</span> age = <span class="number">17</span>;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> List&lt;String&gt; course;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> String address = <span class="string">&quot;chengDu&quot;</span>;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">final</span> String like = <span class="string">&quot;game&quot;</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        Student o = <span class="keyword">new</span> Student();</span><br><span class="line">        System.out.println(ClassLayout.parseInstance(o).toPrintable());</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

   <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">com.hs.test.Student object internals:</span><br><span class="line"> OFFSET  SIZE               TYPE DESCRIPTION                               VALUE</span><br><span class="line">      0     4                    (object header)                           01 00 00 00 (00000001 00000000 00000000 00000000) (1)</span><br><span class="line">      4     4                    (object header)                           00 00 00 00 (00000000 00000000 00000000 00000000) (0)</span><br><span class="line">      8     4                    (object header)                           44 c1 00 f8 (01000100 11000001 00000000 11111000) (-134168252)</span><br><span class="line">     12     4                int Student.age                               17</span><br><span class="line">     16     4   java.lang.String Student.name                              (object)</span><br><span class="line">     20     4   java.lang.String Student.like                              (object)</span><br><span class="line">Instance size: 24 bytes</span><br><span class="line">Space losses: 0 bytes internal + 0 bytes external &#x3D; 0 bytes total</span><br></pre></td></tr></table></figure>

<p>   这里成员变量大小都会在对象内存布局中展示出来,没有静态变量。</p>
<p>​    3.  数组对象</p>
   <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">int</span>[] o = &#123;<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>&#125;;</span><br><span class="line">System.out.println(ClassLayout.parseInstance(o).toPrintable());</span><br></pre></td></tr></table></figure>

   <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">[I object internals:</span><br><span class="line"> OFFSET  SIZE   TYPE DESCRIPTION                               VALUE</span><br><span class="line">      <span class="number">0</span>     <span class="number">4</span>        (object header)                           <span class="number">01</span> <span class="number">00</span> <span class="number">00</span> <span class="number">00</span> (<span class="number">00000001</span> <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">00000000</span>) (<span class="number">1</span>)</span><br><span class="line">      <span class="number">4</span>     <span class="number">4</span>        (object header)                           <span class="number">00</span> <span class="number">00</span> <span class="number">00</span> <span class="number">00</span> (<span class="number">00000000</span> <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">00000000</span>) (<span class="number">0</span>)</span><br><span class="line">      <span class="number">8</span>     <span class="number">4</span>        (object header)                           <span class="number">6d</span> <span class="number">01</span> <span class="number">00</span> f8 (<span class="number">01101101</span> <span class="number">00000001</span> <span class="number">00000000</span> <span class="number">11111000</span>) (-<span class="number">134217363</span>)</span><br><span class="line">     <span class="number">12</span>     <span class="number">4</span>        (object header)                           <span class="number">07</span> <span class="number">00</span> <span class="number">00</span> <span class="number">00</span> (<span class="number">00000111</span> <span class="number">00000000</span> <span class="number">00000000</span> <span class="number">00000000</span>) (<span class="number">7</span>)</span><br><span class="line">     <span class="number">16</span>    <span class="number">28</span>    <span class="keyword">int</span> [I.&lt;elements&gt;                             N/A</span><br><span class="line">     <span class="number">44</span>     <span class="number">4</span>        (loss due to tde next object alignment)</span><br><span class="line">Instance size: <span class="number">48</span> bytes</span><br><span class="line">Space losses: <span class="number">0</span> bytes internal + <span class="number">4</span> bytes external = <span class="number">4</span> bytes total</span><br></pre></td></tr></table></figure>

<p>   这里的</p>
   <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">12     4        (object header)                           07 00 00 00 (00000111 00000000 00000000 00000000) (7)</span><br></pre></td></tr></table></figure>

<p>   显示了对象头包含了数组的length;</p>
<blockquote>
<p>总结：对于对象的内存大小（64位默认开启指针压缩情况下）：</p>
<ul>
<li>普通对象：<ul>
<li>markWord 8byte</li>
<li>klass pointer 4byte</li>
<li>成员变量实际情况来占用</li>
<li>padding = 8的倍数的余数</li>
</ul>
</li>
<li>数组对象：<ul>
<li>多了个length占用4个字节，其它情况与普通对象一致。</li>
</ul>
</li>
</ul>
</blockquote>
<h4 id="四、对象头"><a href="#四、对象头" class="headerlink" title="四、对象头"></a>四、对象头</h4><p>参考<a target="_blank" rel="noopener" href="http://hg.openjdk.java.net/jdk8/jdk8/hotspot/file/87ee5ee27509/src/share/vm/oops/markOop.hpp">markOop.hpp</a></p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//  32 bits:</span></span><br><span class="line"><span class="comment">//  --------</span></span><br><span class="line"><span class="comment">//             hash:25 ------------&gt;| age:4    biased_lock:1 lock:2 (normal object)</span></span><br><span class="line"><span class="comment">//             Javatdread*:23 epoch:2 age:4    biased_lock:1 lock:2 (biased object)</span></span><br><span class="line"><span class="comment">//             size:32 ------------------------------------------&gt;| (CMS free block)</span></span><br><span class="line"><span class="comment">//             PromotedObject*:29 ----------&gt;| promo_bits:3 -----&gt;| (CMS promoted object)</span></span><br><span class="line"><span class="comment">//</span></span><br><span class="line"><span class="comment">//  64 bits:</span></span><br><span class="line"><span class="comment">//  --------</span></span><br><span class="line"><span class="comment">//  unused:25 hash:31 --&gt;| unused:1   age:4    biased_lock:1 lock:2 (normal object)</span></span><br><span class="line"><span class="comment">//  Javatdread*:54 epoch:2 unused:1   age:4    biased_lock:1 lock:2 (biased object)</span></span><br><span class="line"><span class="comment">//  PromotedObject*:61 ---------------------&gt;| promo_bits:3 -----&gt;| (CMS promoted object)</span></span><br><span class="line"><span class="comment">//  size:64 -----------------------------------------------------&gt;| (CMS free block)</span></span><br><span class="line"><span class="comment">//</span></span><br><span class="line"><span class="comment">//  unused:25 hash:31 --&gt;| cms_free:1 age:4    biased_lock:1 lock:2 (COOPs &amp;&amp; normal object)</span></span><br><span class="line"><span class="comment">//  Javatdread*:54 epoch:2 cms_free:1 age:4    biased_lock:1 lock:2 (COOPs &amp;&amp; biased object)</span></span><br><span class="line"><span class="comment">//  narrowOop:32 unused:24 cms_free:1 unused:4 promo_bits:3 -----&gt;| (COOPs &amp;&amp; CMS promoted object)</span></span><br><span class="line"><span class="comment">//  unused:21 size:35 --&gt;| cms_free:1 unused:7 ------------------&gt;| (COOPs &amp;&amp; CMS free block)</span></span><br></pre></td></tr></table></figure>

<p>整理了下：如下64位MarkWord的存储内容，32位存储内容及状态都与64位一致，只是占用大小区别。</p>
<table>
    <tr bgcolor="#66ce78">
        <td>锁状态</td>
        <td>25bit</td>
        <td>31bit</td>
        <td>1bit</td>
        <td>4bit</td>
        <td>1bit偏向锁位</td>
        <td colspan="2">2bit锁标志位</td>
    </tr>
    <tr >
        <td>无状态(new)</td>
        <td>unused</td>
        <td>hashCode(如果有调用)</td>
        <td>unused</td>
        <td>分代年龄</td>
        <td>0</td>
        <td>0</td>
        <td>1</td>
    </tr>
    <tr bgcolor="#49a7d6">
        <td>锁状态</td>
        <td>54bit</td>
        <td>2bit</td>
        <td>1bit</td>
        <td>4bit</td>
        <td>1bit偏向锁位</td>
        <td colspan="2">2bit锁标志位</td>
    </tr>
    <tr >
        <td>偏向锁</td>
        <td>当前线程指针JavaThread*</td>
        <td>Epoch</td>
        <td>unused</td>
        <td>分代年龄</td>
        <td>1</td>
        <td>0</td>
        <td>1</td>
    </tr>
        <tr bgcolor="#597dd2">
        <td>锁状态</td>
        <td colspan="5">62bit</td>
        <td colspan="2">2bit锁标志位</td>
    </tr>
    <tr >
        <td>轻量级锁/自旋锁/无锁</td>
        <td colspan="5">指向线程栈中Lock Record的指针</td>
        <td>0</td>
        <td>0</td>
    </tr>
    <tr>
        <td>重量级锁</td>
        <td colspan="5">指向互斥量(重量级锁)的指针</td>
        <td>1</td>
        <td>0</td>
    </tr>
    <tr>
        <td>GC标记信息</td>
        <td colspan="5">CMS标记过程用到的标记信息</td>
        <td>1</td>
        <td>1</td>
    </tr>
</table>



<h6 id="无锁状态下的markWord"><a href="#无锁状态下的markWord" class="headerlink" title="无锁状态下的markWord"></a>无锁状态下的markWord</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">Object o = <span class="keyword">new</span> Object();</span><br><span class="line">System.out.println(<span class="string">&quot;[hasCode before]&quot;</span>);</span><br><span class="line">System.out.println(ClassLayout.parseInstance(o).toPrintable());</span><br><span class="line">System.out.println(<span class="string">&quot;[hasCode after]&quot;</span>);</span><br><span class="line">o.hashCode();</span><br><span class="line">System.out.println(ClassLayout.parseInstance(o).toPrintable());</span><br></pre></td></tr></table></figure>

<p><img src="https://pic.downk.cc/item/5f81da4d1cd1bbb86b7c9501.jpg" alt="IMG"></p>
<p>这里是小端存储，倒序查看二进制位</p>
<ul>
<li>这里在hashCode后，31bit为hashCode占用，剩余的为:</li>
</ul>
<p><img src="https://pic.downk.cc/item/5f8317151cd1bbb86b658262.jpg" alt="IMG"></p>
<p>这里GC年龄只有4位，所以说GC年龄最大15岁。</p>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%AF%B9%E8%B1%A1%E5%A4%B4/" rel="tag">对象头</a></li></ul>

    </footer>
  </div>

    
 
   
</article>

    
    <article
  id="post-tomcat性能提升之Apr"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2020/10/07/tomcat%E6%80%A7%E8%83%BD%E6%8F%90%E5%8D%87%E4%B9%8BApr/"
    >tomcat性能提升之Apr</a> 
</h2>
 

    </header>
     
    <div class="article-meta">
      <a href="/2020/10/07/tomcat%E6%80%A7%E8%83%BD%E6%8F%90%E5%8D%87%E4%B9%8BApr/" class="article-date">
  <time datetime="2020-10-07T15:06:15.000Z" itemprop="datePublished">2020-10-07</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/tomcat/">tomcat</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h5 id="为啥用APR协议？"><a href="#为啥用APR协议？" class="headerlink" title="为啥用APR协议？"></a>为啥用APR协议？</h5><p>tomcat有三种协议    </p>
<ul>
<li>BIO</li>
<li>NIO</li>
<li>APR</li>
</ul>
<p>现目前tomcat8中protocol默认为：“HTTP/1.1”，它自己会根据你的tomcat版本开启NIO，所以NIO这种就不需要手动声明为NIO，比如：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">protocol&#x3D;&quot;org.apache.coyote.http11.Http11NioProtocol&quot;</span><br></pre></td></tr></table></figure>
<p>手动开启NIO模式。<br>为啥用APR就不研究了，根据压测结果来看，确实有所提升，但比起NIO，效果不是非常大。</p>
<h5 id="安装依赖库"><a href="#安装依赖库" class="headerlink" title="安装依赖库"></a>安装依赖库</h5><p>要使用APR需要APR相关，还有tomcat-native</p>
<ul>
<li>apr</li>
<li>tomcat-native<br>如用到SSL相关还需要SSL依赖包，我这里没用。</li>
</ul>
<h6 id="环境-生产环境无ROOT"><a href="#环境-生产环境无ROOT" class="headerlink" title="环境[生产环境无ROOT]"></a>环境[生产环境无ROOT]</h6><p>CentOs 7.6.18.10<br>源码包版本：   </p>
<ul>
<li>apr-1.7.0.tar.gz</li>
<li>apr-iconv-1.2.2.tar.gz</li>
<li>apr-util-1.6.1.tar.gz         </li>
<li>tomcat-native-xx(这个玩意tomcat包lib中有)</li>
</ul>
<p>其中apr-util-1.6.1.tar.gz依赖于expat-2.2.9.tar.gz</p>
<p>源码包安装路径/app/aprcom<br>默认已解压</p>
<ol>
<li>安装apr<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">.&#x2F;configure --prefix&#x3D;&#x2F;app&#x2F;aprcom&#x2F;apr</span><br><span class="line">make &amp;&amp; make install</span><br></pre></td></tr></table></figure></li>
<li>安装apr-iconv<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">.&#x2F;configure --prefix&#x3D;&#x2F;app&#x2F;aprcom&#x2F;apr-iconv --with-apr&#x3D;&#x2F;app&#x2F;aprcom&#x2F;apr</span><br><span class="line">make &amp;&amp; make install</span><br></pre></td></tr></table></figure></li>
<li>安装expat(可以先执行第四部，不报expat相关错就不用装了)<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">.&#x2F;configure --prefix&#x3D;&#x2F;app&#x2F;aprcom&#x2F;expat</span><br><span class="line">make &amp;&amp; make install</span><br></pre></td></tr></table></figure></li>
<li>安装apr-util<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">.&#x2F;configure --prefix&#x3D;&#x2F;app&#x2F;aprcom&#x2F;apr-util --with-apr&#x3D;&#x2F;app&#x2F;aprcom&#x2F;apr --with-apr-iconv&#x3D;&#x2F;app&#x2F;aprcom&#x2F;apr-iconv&#x2F;bin&#x2F;apriconv --with-expat&#x3D;&#x2F;app&#x2F;aprcom&#x2F;expat</span><br><span class="line">make &amp;&amp; make install</span><br></pre></td></tr></table></figure></li>
<li>安装tomcat-native<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">.&#x2F;configure  --prefix&#x3D;&#x2F;app&#x2F;aprcom&#x2F;tomcat --with-apr&#x3D;&#x2F;app&#x2F;aprcom&#x2F; --with-java-home&#x3D;&#x2F;usr&#x2F;java&#x2F;jdk1.8</span><br><span class="line">make &amp;&amp; make install</span><br></pre></td></tr></table></figure>
如有失败的，在重新./configure前请先make clean操作</li>
</ol>
<h6 id="环境变量配置"><a href="#环境变量配置" class="headerlink" title="环境变量配置"></a>环境变量配置</h6><p>配置环境变量，使其指定Lib包运行tomcat<br>方式一： 通过启动脚本添加</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">#找到tomcat的启动脚本，我这里直接在catalina.sh增加的</span><br><span class="line">JAVA_OPTS&#x3D;&quot;$JAVA_OPTS -Djava.library.path&#x3D;&#x2F;app&#x2F;aprcom&#x2F;apr&#x2F;lib -Djava.library.path&#x3D;&#x2F;app&#x2F;aprcom&#x2F;tomcat&#x2F;lib&quot;</span><br></pre></td></tr></table></figure>

<p>方式二: 通过profile环境变量配置文件修改</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">cd ~</span><br><span class="line">vi .bash_profile</span><br><span class="line">export LD_LIBRARY_PATH&#x3D;&#x2F;app&#x2F;aprcom&#x2F;apr&#x2F;lib:&#x2F;app&#x2F;aprcom&#x2F;tomcat&#x2F;lib:LD_LIBRARY_PATH</span><br><span class="line">export LD_RUN_PATH&#x3D;&#x2F;app&#x2F;aprcom&#x2F;apr&#x2F;lib:&#x2F;app&#x2F;aprcom&#x2F;tomcat&#x2F;lib:$LD_RUN_PATH</span><br><span class="line">保存后</span><br><span class="line">source .bash_profile</span><br></pre></td></tr></table></figure>


<h5 id="配置相关"><a href="#配置相关" class="headerlink" title="配置相关"></a>配置相关</h5><p>1.我这里不用SSL，先关闭</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"># vi server.xml</span><br><span class="line"></span><br><span class="line">&lt;Listener className&#x3D;&quot;org.apache.catalina.core.AprLifecycleListener&quot; SSLEngine&#x3D;&quot;off&quot; &#x2F;&gt;</span><br></pre></td></tr></table></figure>
<p>2.开启APR模式</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># vi server.xml</span><br><span class="line">&lt;Connector port&#x3D;&quot;8080&quot; protocol&#x3D;&quot;org.apache.coyote.http11.Http11AprProtocol&quot;</span><br></pre></td></tr></table></figure>
<p>3.启动即可，日志中会有apr相关的东西</p>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/tomcat/" rel="tag">tomcat</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%8E%8B%E6%B5%8B/" rel="tag">压测</a></li></ul>

    </footer>
  </div>

    
 
   
</article>

    
    <article
  id="post-about"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2020/10/07/about/"
    >关于我</a> 
</h2>
 

    </header>
     
    <div class="article-meta">
      <a href="/2020/10/07/about/" class="article-date">
  <time datetime="2020-10-07T04:52:55.000Z" itemprop="datePublished">2020-10-07</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <blockquote>
<p>A developer, live in ChengDu, China. </p>
</blockquote>
<p>普普通通打杂小子</p>
<p>微信: hsir34</p>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%85%B3%E4%BA%8E%E6%88%91/" rel="tag">关于我</a></li></ul>

    </footer>
  </div>

    
 
   
</article>

    
    <article
  id="post-Hexo使用记录"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2020/10/06/Hexo%E4%BD%BF%E7%94%A8%E8%AE%B0%E5%BD%95/"
    >Hexo使用记录</a> 
</h2>
 

    </header>
     
    <div class="article-meta">
      <a href="/2020/10/06/Hexo%E4%BD%BF%E7%94%A8%E8%AE%B0%E5%BD%95/" class="article-date">
  <time datetime="2020-10-06T12:42:45.010Z" itemprop="datePublished">2020-10-06</time>
</a>    
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h5 id="新建gitee仓库"><a href="#新建gitee仓库" class="headerlink" title="新建gitee仓库"></a>新建gitee仓库</h5><p>​    如果需要显示为  sknoend.gitee.io这样的，创建的时候一定就直接建 sknoend这个名字就可以了</p>
<h5 id="HEXO"><a href="#HEXO" class="headerlink" title="HEXO"></a>HEXO</h5><p>官方网站：<a target="_blank" rel="noopener" href="https://hexo.io/zh-cn/docs/">https://hexo.io/zh-cn/docs/</a></p>
<p>Ayer主题：<a target="_blank" rel="noopener" href="https://shen-yu.gitee.io/2019/ayer/">https://shen-yu.gitee.io/2019/ayer/</a></p>
<p>图床 ： <a target="_blank" rel="noopener" href="https://www.superbed.cn/">https://www.superbed.cn/</a></p>
<h5 id="注意事项"><a href="#注意事项" class="headerlink" title="注意事项"></a>注意事项</h5><ol>
<li><p>在修改配置文件时候，备份_config.yml类似文件，不要直接改成 _config.yml_bak 名备份，这个导致我使用hexo g报错，查了半天才发现是这个原因。</p>
</li>
<li><p>关于标签与分类</p>
<ul>
<li>标签及分类生成</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">   hexo new page &quot;tags&quot;</span><br><span class="line">   hexo new page &quot;categories&quot;</span><br><span class="line">   </span><br><span class="line"><span class="meta">   #</span><span class="bash">修改\<span class="built_in">source</span>\categories\index.md为：</span></span><br><span class="line">   title: 文章分类</span><br><span class="line">   date: 2020-10-07 23:19:38</span><br><span class="line">   type: &quot;categories&quot;</span><br><span class="line">   layout: &quot;categories&quot;</span><br><span class="line"><span class="meta">   #</span><span class="bash">修改\<span class="built_in">source</span>\tags\index.md为：</span></span><br><span class="line">   title: tags</span><br><span class="line">   date: 2020-10-07 11:00:38</span><br><span class="line">   type: &quot;tags&quot;</span><br><span class="line">   layout: &quot;tags&quot;</span><br><span class="line"><span class="meta">   #</span><span class="bash">\<span class="built_in">source</span>\friends\index.md也需要设置,不然不生效</span></span><br><span class="line">layout: &quot;friends&quot;</span><br></pre></td></tr></table></figure>

<ul>
<li><p>模板配置</p>
<p>​    为了新建文章的时候自带分类及标签，需设置</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"> #</span><span class="bash">\scaffolds\post.md</span></span><br><span class="line"> title: &#123;&#123; title &#125;&#125;</span><br><span class="line"> date: &#123;&#123; date &#125;&#125;</span><br><span class="line"> categories:</span><br><span class="line">tags:</span><br></pre></td></tr></table></figure>





</li>
</ul>
</li>
</ol>
<h5 id="相关命令"><a href="#相关命令" class="headerlink" title="相关命令"></a>相关命令</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">编写文章</span></span><br><span class="line">hexo new post title</span><br><span class="line"></span><br><span class="line">hexo clean</span><br><span class="line"><span class="meta">#</span><span class="bash">生成页面</span></span><br><span class="line">hexo g </span><br><span class="line"><span class="meta">#</span><span class="bash">启动服务</span></span><br><span class="line">hexo s</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash">部署到gitee</span></span><br><span class="line">hexo d -g</span><br></pre></td></tr></table></figure>



 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/hexo/" rel="tag">hexo</a></li></ul>

    </footer>
  </div>

    
 
   
</article>

    
  </article>
  

  
</section>
</div>

      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2019-2020
        <i class="ri-heart-fill heart_icon"></i> John Doe
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        由 <a href="https://hexo.io" target="_blank">Hexo</a> 强力驱动
        <span class="division">|</span>
        主题 - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1279327628&amp;web_id=1279327628'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="光"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友链</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/2020/10/07/about/">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="搜索">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="https://pic.imgdb.cn/item/5f7c7f6c160a154a6704a13b.png">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="https://pic.imgdb.cn/item/5f7c7fd4160a154a6704b975.png">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>

<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->


<link rel="stylesheet" href="/css/clipboard.css">

<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>


<!-- CanvasBackground -->


    
  </div>
</body>

</html>